package pack0831;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

//第三种多线程实现方式,实现Callable 接口，有一个返回结果
public class DemoD {
    public static void main(String[] args) throws Exception{
        DemoD1 dd1 = new DemoD1();
        FutureTask ft1 = new FutureTask(dd1);
        Thread t1 = new Thread(ft1);
        t1.start();
        Object s1 = ft1.get();
        System.out.println(s1);

        DemoD2 dd2 = new DemoD2();
        FutureTask ft2 = new FutureTask(dd2);
        Thread t2 = new Thread(ft2);
        t2.start();
        Object s2 = ft2.get();
        System.out.println(s2);
    }
}
class DemoD1 implements Callable {
    @Override
    public Object call() throws Exception {
        System.out.println("我是"+Thread.currentThread().getName());
        return "abc";
    }
}
class DemoD2 implements Callable{
    @Override
    public Object call() throws Exception {
        System.out.println("我是"+Thread.currentThread().getName());
        return "123";
    }
}
